﻿#ifndef ACCEPTOR_H
#define ACCEPTOR_H

#include "socket.h"
#include <memory> 
#include <functional>

class EventLoop;
class Channel;

class Acceptor
{
private:
    // 监听套接字
    Socket m_socket;
    // 事件循环
    EventLoop *m_eloop;
    // 监听描述符
    std::unique_ptr<Channel> m_listenChannel;
    // 新连接回调
    using AcceptCallBack = std::function<void(int)>;
    AcceptCallBack m_acceptCb;

private:
    // 处理新连接
    void handleRead();
    // 创建服务器
    int createServer(uint16_t port, const std::string& ip);
public:
    Acceptor(EventLoop *eloop, uint16_t port, const std::string& ip);
    ~Acceptor();
    // 监听
    void listen();
    // 设置新连接回调
    void setNewConnectionCallback(AcceptCallBack callback);
    
};
#endif
